package com.java.androidmarket.service.impl;

import com.java.androidmarket.dao.CommentDao;
import com.java.androidmarket.entity.Comment;
import com.java.androidmarket.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * description:
 * author:张腾
 * date:2021-04-24
 */

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentDao commentDao;

    @Override
    public List<Comment> getComment(int goodsId) {

        List<Comment> comments = commentDao.getComment(goodsId);
        for (Comment comment : comments) {
            comment.getUser().setUserImg("http://192.168.205.54:8989/"+comment.getUser().getUserImg());
        }
        return comments;
    }

    @Override
    public void addComment(Comment comment) {
        //获取当前时间
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        comment.setCommentTime(now.format(formatter));
        commentDao.addComment(comment);
    }
}
